<%@ include file="/WEB-INF/jsp/includes.jsp" %>
<%@ include file="/WEB-INF/jsp/header.jsp" %>


<h2><fmt:message key="album.albums"/>:</h2>
<script language="javascript">
    //<!--
    function deleteAlbum(url) {
        var confirmed = confirm('<fmt:message key="album.list.form.confirmDelete"/>');

        if (confirmed) {
            var request = new XMLHttpRequest();
            request.open('DELETE', url, true);
            request.onreadystatechange = function() {
                //Handler function for call back on state change.
                if (request.readyState == 4) {
                    window.location.reload(true);
                }
            }
            request.send(null);
        }
    }
    // -->
</script>

<table>
    <thead>
    <th><fmt:message key="album.name"/></th>
    <th><fmt:message key="album.creation.date"/></th>
    <th><fmt:message key="album.modify.date"/></th>
    <th><fmt:message key="album.publish.date"/></th>
    <th><fmt:message key="album.public"/></th>
    <th><fmt:message key="album.button.delete"/></th>
    </thead>
    <c:forEach var="album" items="${selections}">
        <tr>
            <td>
                <spring:url value="/albums/{albumId}" var="albumUrl">
                    <spring:param name="albumId" value="${album.id}"/>
                </spring:url>
                <a href="${fn:escapeXml(albumUrl)}">${album.name}</a>
            </td>
            <td>${album.creationDate}</td>
            <td>${album.modifyDate}</td>
            <td>${album.publishDate}</td>
            <td>${album.isPublic}</td>
            <td>
                <spring:url value="/albums/{albumId}/delete" var="albumDeleteUrl">
                    <spring:param name="albumId" value="${album.id}"/>
                </spring:url>
                <a href="javascript:deleteAlbum('<c:out value="${fn:escapeXml(albumDeleteUrl)}"/>')"><fmt:message key="album.button.delete"/></a>

                    <%--<td>
                      <c:forEach var="image" items="${image.images}">
                        ${image.name} &nbsp;
                      </c:forEach>
                    </td>--%>
        </tr>
    </c:forEach>
</table>
<%--
<sec:authorize ifAllGranted="ROLE_ADMIN">
--%>

<table>
    <tr>
        <td>
            <spring:url value="/albums/new" var="newAlbumUrl"/>
            <a href="${fn:escapeXml(newAlbumUrl)}"><fmt:message key="album.button.new"/></a>
        </td>
    </tr>
</table>
<%--
</sec:authorize>
--%>

<%@ include file="/WEB-INF/jsp/footer.jsp" %>
